#!/bin/bash
#
# rsyncd      This shell script takes care of starting and stopping
#             standalone rsync.
#
# chkconfig: - 99 50
# description: rsync is a file transport daemon
# processname: rsync
# config: /etc/rsyncd.conf

# Source function library
#. /etc/rc.d/init.d/functions

RETVAL=0
prog="rsync"
OPTIONS="--daemon  --config=/opt/rsyncd/etc/rsyncd.conf"
PPATH="/opt/rsyncd/bin/"
CFILE="/opt/rsyncd/etc/rsyncd.conf"
PID="/opt/rsyncd/run/rsyncd.pid"

start() {
        # Start daemons.
          pkill rsync
        [ -x $PPATH$prog ] || { echo 'FATAL: No such programme';exit 4; }
        [ -f $CFILE ] || { echo "FATAL: config file does not exist";exit 6; }
        echo -n $"Starting $prog: "
        $PPATH$prog $OPTIONS
          netstat -tupln  | grep $prog
        RETVAL=$?
        [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
        echo
        return $RETVAL
}

stop() {
        # Stop daemons.
        echo -n $"Shutting down $prog: "
          pkill $prog
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && rm -f  
        return $RETVAL
}

# call the function we defined
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  restart|reload)
        stop
        start
        RETVAL=$?
        ;;
  status)
        status $prog
        RETVAL=$?
        ;;
  *)
        echo $"Usage: $0 {start|stop|restart|reload|status}"
        exit 2
esac

exit $RETVAL
